﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using SdmxMl.Common;
using SdmxMl.Helper;
using SdmxMl.Manager;
using SdmxMl.Multiplexor;
using SdmxMl.Panels;

namespace SdmxMl.Manager
{
    public class OwnerGroupHelper
    {
        public string SelectOwner()
        {
            string ownerId = string.Empty;

            using (new CWaitCursor())
            {

                List<string> ownerGroups = Mux.Instance.UserOwnerList();
                if (ownerGroups.Count == 0)
                    throw new ApplicationException("User is not associated to owner groups");
                if (ownerGroups.Count > 1)
                {
                    DlgGetFromList aDlg = new DlgGetFromList(ownerGroups);
                    if (aDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        ownerId = aDlg.Group;
                }
                else
                    ownerId = ownerGroups[0];
            }

            return ownerId;
        }

        public void UpdateOwner(SdmxArtefactType arType, string fullId, string ownerId)
        {
            if (string.IsNullOrEmpty(ownerId) == false)
            {
                Mux.Instance.UpdateOwner(arType.ToString(), fullId, ownerId);
            }
        }
    }
}
